'use strict';
import React, {
    Component
} from 'react'
import {
    Link
} from 'react-router'
import {
    localData
} from '../Tools/index';
import Header from './Common/Header'
import {
    HttpService,
    funcCheck
} from '../Tools'
import {
    goJxtUrl
} from '../Tool'
import {
    taskFinish
} from '../Tools'
import News from './News'
import ConfirmBox from './Common/ConfirmBox'

import notice from '../img/icon/xlgg.png'
import taskPublish from '../img/icon/taskPublish_index.png'
import task from '../img/icon/task_index.png'
import classAlbum from '../img/icon/classAlbum_index.png'
import phoneDirectories from '../img/icon/phoneDirectories_index.png'
import score from '../img/icon/score_index.png'
import growthRecord from '../img/icon/growthRecord_index.png'
import imgMore from '../img/icon/morefn.png'
import imgNtc from '../img/icon/notice_index.png'
import imgKaoqin from '../img/icon/kaoqin.png'
import subjectTimetable from '../img/icon/subjectTimetable_index.png'

import zixun from '../img/zixun.png'
import yuanding from '../img/icon/yuanding.png'

export default class Teacher extends Component {
    constructor(props) {
        super(props);
        this.state = {
            integral: sessionStorage.integral == 'true'
        }
    }

    componentWillMount() {
        delete localData.TeacherAtt;
    }
    jxtLink(url, e) {
        const data = `wherefrom=weixin&appToken=${localStorage.appToken}&appType=${[2, 3, 1][this.props.params.type - 1]}&phone=${localStorage.userphone}`
        let newUrl = goJxtUrl + '/jiaxiaotong/#' + url + '?' + data;
        if (e.currentTarget.className == 'yuanding')
            newUrl = 'integral.html#/integral?' + data
        location.href = newUrl
    }
    integral(status) {
        if (status.toString() == sessionStorage.integral)
            return
        sessionStorage.integral = status
        this.setState({
            integral: status
        })
        taskFinish('今日登录', (status, config) => {
            if (status) {
                this.config = config;
                this.setState({
                    show: 1
                })
            }
        })
    }

    render() {
        const {
            type
        } = this.props.params
        const {
            integral
        } = this.state
        return (
            <div className="index_page ptop">
                <Header title='随寻通教师端' toLink={`/login/0/jxt/${localStorage.appToken}`} />
                <News length='1' sign={type} integral={this.integral.bind(this)} />
                <ul className='indexlist clearfix' >
                    <li className='index'>
                        {type==1?
                        <Link to='/notice'>
                            <img src={imgNtc}/>
                            <span>班级通知</span>
                        </Link>
                        :<div onClick={this.jxtLink.bind(this,'/SubjectTimetable')}>
                            <img src={subjectTimetable}/>
                            <span>班级课表</span>
                        </div>}
                    </li>
                    {/*<li className='index'>
                        <a href={`${goJxtUrl}/#/info?wherefrom=weixin&appToken=${localStorage.appToken}&userphone=${localStorage.userphone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')}`}>
                            <img src={zixun}/>
                            <span>资讯</span>
                        </a>
                    </li>*/}
                    <li className='index'>
                        {
                            integral?
                            <div onClick={this.jxtLink.bind(this,'/GrowthRecord')} className='yuanding'>
                                <img src={yuanding}/>
                                <span>园丁园</span>
                            </div>:
                            <div onClick={this.jxtLink.bind(this,'/GrowthRecord')}>
                                <img src={growthRecord}/>
                                <span>成长记录</span>
                            </div>
                        }
                    </li>

                    <li className='index'>
                        <Link to='/TeacherAtt'>
                            <img src={imgKaoqin}/>
                            <span>考勤信息</span>
                        </Link>
                    </li>
                    <li className='index'>
                        <div onClick={this.jxtLink.bind(this,'/Notice')}>
                            <img src={notice}/>
                            <span>校内公告</span>
                        </div>
                    </li>
                    <li className='index'>
                        <div onClick={this.jxtLink.bind(this,'/TaskPublish')}>
                            <img src={taskPublish}/>
                            <span>布置作业</span>
                        </div>
                    </li>
                    <li className='index'>
                        <div onClick={this.jxtLink.bind(this,'/Task')}>
                            <img src={task}/>
                            <span>家庭作业</span>
                        </div>
                    </li>
                    <li className='index'>
                        <div onClick={this.jxtLink.bind(this,'/Score')}>
                            <img src={score}/>
                            <span>成绩管理</span>
                        </div>
                    </li>
                    <li className='index'>
                        <Link to={`/teachermore/${type}/${integral}`}>
                            <img src={imgMore}/>
                            <span>更多</span>
                        </Link>
                    </li>
                </ul>
                <ConfirmBox config={this.config} show={this.state.show} sigle='1'/>
            </div>
        )
    }
}
